<extend name="base"/>

<block name="main">

    <div class="xt-xx">
        <div class="xx-tab">
            <div onclick="checkType(this, 0)" class="xxt-btn {$activeIndex == 0 ? 'active' : ''}">未读</div>
            <div onclick="checkType(this, 1)" class="xxt-btn {$activeIndex == 1 ? 'active' : ''}">已读</div>
            <div class="clear"></div>
        </div>

        <div class="xx-list">
            <volist name="data" id="vo">
                <div class="xxl-box" onclick="href('{$vo.type}', '{$vo.id}')">
                    <div class="xxlb-sj">{$vo.create_time}</div>
                    <text class="xxlb-bt">
                        <if condition="$vo['type'] == 1">
                            优惠券消息
                            <elseif condition="$vo['type'] == 2"/>
                            快递消息
                            <else/>
                            系统消息
                        </if>
                    </text>
                    <div class="xxlb-img">
                        <if condition="$vo['type'] == 1">
                            <img src='__HELPER_IMG__/icon_xt1.png'></img>
                            <elseif condition="$vo['type'] == 2"/>
                            <img src='__HELPER_IMG__/icon_xt2.png'></img>
                            <else/>
                            <img src='__HELPER_IMG__/icon_xt3.png'></img>
                        </if>
                    </div>
                    <text class="xxlb-wz">{$vo.title} ></text>
                    <div class="clear"></div>
                </div>
            </volist>
        </div>
    </div>
</block>

<block name="js">
    <script>
        var url = 'Apis/msgList';
        var param = {};

        function checkType(that, type)
        {
            $('.xxt-btn').removeClass('active');
            $(that).addClass('active');

            $.showLoading('数据加载中');

            scroll(0, 0);//滚动条滑动至最顶端
            initLoad();

            param.uid = '{$Think.session.uid}';
            param.type = type;

            post_ajax(url, param, function (res) {
                if (res.result == 1) {
                    var list = res.data;

                    var html = readerHtml(list);
                    $('.xx-list').html(html);
                } else {
                    $('.xx-list').html('');
                    layer.msg(res.msg);
                }
            })
        }

        /**
         * 分页加载更多
         * */
        load(url, param, function (res){
            var list = res.data.list;
            if(list.length > 0){
                ++page;
                pageLoading = false;

                var html = readerHtml(list);
                $('.xx-list').append(html);
            }else{
                layer.msg('暂无更多数据');
            }
        });

        function readerHtml(list)
        {
            var html = '';
            if (list.length > 0) {
                list.forEach(function (val) {
                    if(val.type == 1){
                        var msg_desc = '优惠券消息';
                        var img_src = '__HELPER_IMG__/icon_xt1.png';
                    }else if(val.type == 2){
                        var msg_desc = '快递消息';
                        var img_src = '__HELPER_IMG__/icon_xt2.png';
                    }else{
                        var msg_desc = '系统消息';
                        var img_src = '__HELPER_IMG__/icon_xt3.png';
                    }

                    html += '<div class="xxl-box" onclick="href('+ val.type +', '+ val.id +')">\n' +
                        '                    <div class="xxlb-sj">'+ val.create_time +'</div>\n' +
                        '                    <text class="xxlb-bt">\n' +
                        '                        '+ msg_desc +'\n' +
                        '                    </text>\n' +
                        '                    <div class="xxlb-img">\n' +
                    '                            <img src="'+ img_src +'"></img>\n' +
                        '                    </div>\n' +
                        '                    <text class="xxlb-wz">'+ val.title +'</text>\n' +
                        '                    <div class="clear"></div>\n' +
                        '                </div>';
                })
            }
            return html;
        }

        function href(type, id) {
            var uid = "{$Think.session.uid}";

            if (type == 1) {
                //跳转到券列表
                window.location.href = "{:U('my_wdkb')}";
            } else if (type == 2) {

            } else if (type == 3) {
                //跳转到系统消息
                window.location.href = "/index.php/Home/Helper/my_msg_page?id=" + id + "&status=" + type;
            }

            $.showLoading('数据加载中');

            post_ajax("/Apis/msgDetail",{
                id: id,
                uid: uid,
                type: type
            }, function (res){
            })
        }
    </script>
</block>


